<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新冠后台管理-登陆</title>
    <link rel="icon" href="/images/favicon.ico">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script src="https://www.layuicdn.com/layui-v2.6.8/layui.js"></script>
    <script type="text/javascript" src="/js/jquery.particleground.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.6.8/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/css/login.css">
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item logo-title">
                    <h1>新冠信息后台登录</h1>
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username" for="username"></label>
                    <input type="text" name="userName" lay-verify="required|account" placeholder="用户名或者邮箱"
                           autocomplete="off" class="layui-input" value="123456">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="password"></label>
                    <input type="password" name="userPassWord" lay-verify="required|password" placeholder="密码"
                           autocomplete="off" class="layui-input" value="123456">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-vercode" for="captcha"></label>
                    <input type="text" name="captcha" lay-verify="required|captcha" placeholder="图形验证码"
                           autocomplete="off" class="layui-input verification captcha" value="">
                    <div class="captcha-img">
                        <img src="/captcha" id="captcha" width="130px" height="48px" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <input type="checkbox" name="rememberMe" value="true" lay-skin="primary" title="记住密码">
                </div>
                <div class="layui-form-item">
                    <button id="btn-login" class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit=""
                            lay-filter="login">登 入
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //鼠标单击验证码刷新验证码
    $("#captcha").click(function () {
        $("#captcha").attr("src",'captcha?date=' + new Date().getTime());
    })

    layui.use(['form'], function () {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        // 登录过期的时候，跳出ifram框架
        if (top.location != self.location) top.location = self.location;

        // 粒子线条背景
        $(document).ready(function () {
            $('.layui-container').particleground({
                dotColor: '#7ec7fd',
                lineColor: '#7ec7fd'
            });
        });

        // 进行登录操作
        form.on('submit(login)', function (data) {
            //将登录按钮不可用
            $("#btn-login").attr("disabled","disabled").addClass("layui-btn-disabled");

            data = data.field;
            if (data.userName == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.userPassWord == '') {
                layer.msg('密码不能为空');
                return false;
            }
            if (data.captcha == '') {
                layer.msg('验证码不能为空');
                return false;
            }

            //异步登录请求
            var url = "/loginIf"
            $.post(url, data, function (respones) {
                console.log(respones);
                if (respones.code == 0) {
                    layer.msg('登录成功', {
                        icon: 1,
                        anim: 0,
                        time: 2000 //2秒关闭(如果不配置，默认是3秒)
                    }, function () {
                        window.location = '/main';
                    });
                } else {
                    layer.msg(respones.message, {
                        icon: 2,
                        anim: 0,
                        time: 2000 //2秒关闭(如果不配置，默认是3秒)
                    });
                    //将登录取消不可用
                    $("#btn-login").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                }
            })

            return false;

        });
    });
</script>
</body>
</html>